/**
 * BillApi.java
 * com.aabill.api
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2012-7-24 		wangjieming
 *
 * Copyright (c) 2012, TNT All Rights Reserved.
 */

package com.jamin.aabill.api;

import com.jamin.aabill.data.Circle;
import com.jamin.aabill.data.CircleDelete;
import com.jamin.aabill.data.CircleList;
import com.jamin.aabill.data.LoginResult;
import com.jamin.aabill.data.RegisterResult;
import com.jamin.aabill.http.BillHttpClient;

/**
 * ClassName:BillApi
 *
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-7-24 下午3:47:36 
 */
public class BillApi extends BaseBillApi{


	BillHttpClient httpClient = null;
	private static BillApi billApi = null;


	public static synchronized BillApi getInstance(){
		if(billApi != null){
			return billApi;
		}else{
			return new BillApi();
		}
	}



	private BillApi(){
		httpClient = new BillHttpClient();
	}


	//-------------------------------登录,注册接口,用户信息
	//---------注册
	/**
	 * 注册接口<br>
	 * @param name			名字
	 * @param phoneNum		号码
	 * @param email			邮箱
	 * @param password		密码
	 * @param session
	 * @return
	 * @throws BillException
	 */
	public RegisterResult getRegisterResult(String name,String phoneNum , 
			String email , String password) throws BillException{
		return new RegisterResult(httpClient.post(HOST + METHOD_REGISTER, getRegisterParameter( name, phoneNum , 
				email ,  password), null));
	}


	//---------登录
	/**
	 * 登录方法<br>
	 * @param name		
	 * @param password
	 * @param session
	 * @return
	 * @throws BillException
	 */
	public LoginResult getLoginResult(String name, String password) throws BillException{
		return new LoginResult(
				httpClient.post(HOST + METHOD_LOGIN, getLoginParameter( name ,  password), null ));
	}


	//	/**
	//	 * 得到用户信息接口<br>
	//	 * @param userid
	//	 * @param session
	//	 * @return
	//	 * @throws BillException
	//	 */
	//	public String getUserDetail(String userid,String session) throws BillException{
	//		return httpClient.post(HOST + METHOD_USER_DETAIL, getUserDetailParameter( userid ),session).asString();
	//	}
	//
	//	
	//	private PostParameter[] getUserDetailParameter(String userid ){
	//		PostParameter [] postParameter = new PostParameter[0];
	//		return postParameter;
	//	}


	//-------------------------------圈子列表，创建圈子，
	//-----得到圈子列表
	/**
	 * 得到圈子列表的接口<br>
	 * @param session
	 * @return
	 * @throws BillException
	 */
	public CircleList getCircleList(String session) throws BillException{
		return new CircleList(httpClient.post(HOST + METHOD_CIRCLES, getCircleParameter(), session));
	}


	//-----创建圈子
	/**
	 * 
	 * @method getCreateCircle
	 * @param name
	 * @param description
	 * @param session
	 * @return
	 * @throws BillException
	 * @throws 
	 * @since v1.0
	 */
	public Circle getCreateCircle(String name, String description, String session) throws BillException{
		return new Circle(httpClient.post(HOST + METHOD_CREATE_CIRCLES, getCreateCircleParameter( name, description ), session));
	}


	//-----修改圈子信息
	/**
	 * 
	 * @method getEditCircle
	 * @param id
	 * @param name
	 * @param description
	 * @param active
	 * @param session
	 * @return
	 * @throws BillException
	 * @throws 
	 * @since v1.0
	 */
	public Circle getEditCircle(String id , String name, String description, int active, String session) throws BillException{
		return new Circle(httpClient.post(HOST + METHOD_EDIT_CIRCLES, getEditCircleParameter(id, name, description , active), session));
	}


	//------删除Circle
	/**
	 * 
	 * @method getDeleteCircle
	 * @param id
	 * @param session
	 * @return
	 * @throws BillException
	 * @throws 
	 * @since v1.0
	 */
	public CircleDelete getDeleteCircle(String id , String session) throws BillException{
		return new CircleDelete(httpClient.post(HOST + METHOD_DELETE_CIRCLES, getDeleteCircleParameter(id), session));
	}



	//-----增加Circle成员

	/**
	 * 
	 * @method getInsertMember
	 * @param circleMember
	 * @param session
	 * @return
	 * @throws BillException
	 * @throws 
	 * @since v1.0
	 */
	public String getInsertMember(String  circleMember, String session) throws BillException{
		return httpClient.post(HOST + METHOD_INSERT_MEMBER, getInsertMemberParameter(circleMember), session).asString();
	}





}

